import {get, ID, post, STATION} from "./common";
import {reactive} from "vue";


//根据护士站id获取定时广播列表
const getBroadcastList = () => {
    return get('/station/broadcast/getAll', ID);
};

//根据表单内容添加定时广播
const addBroadcast = (form) => {
    //this.$set(form, 'stationId', STATION.id);
    Object.assign(form, {'stationId': STATION.id});
    return post('/station/broadcast/add', form);
};

//根据表单内容更新定时广播
const updateBroadcast = (form) => {
    return post('/station/broadcast/update', form);
}

//根据定时广播id进行删除
const removeBroadcast = (id) => {
    const param = reactive({
        'id': id
    })
    return get('/station/broadcast/remove', param);
}

//根据护士站id获取语音库列表
const getVoiceList = () => {
    return get('/station/voice/getAll', ID);
};

//增加语音
const addVoice = (form) => {
    Object.assign(form, {'stationId': STATION.id});
    return post('/station/voice/add', form);
}

//根据语音id进行删除
const removeVoice = (id) => {
    return get('/station/voice/remove?id=' + id, null);
}

//根据护士站id查询病人
const getPatientList = () => {
    return get('/station/getAllPatientInfo', ID);
}

//根据音频地址和病人id发送喊话请求
const shoutSubmit = (params) => {
    Object.assign(params, {'id': STATION.id});
    return post('/station/shout/submit', params);
}

//根据type设置有效期
//上传音频文件，返回音频url
const upload = (file) => {
    let data = new FormData();
    data.append("bucketName", "audio");
    data.append('file', file);
    return post('/demo/upload', data, {"Content-Type":"multipart/form-data"});
}


export {
    getVoiceList,
    addBroadcast,
    updateBroadcast,
    removeBroadcast,
    addVoice,
    removeVoice,
    getBroadcastList,
    getPatientList,
    shoutSubmit,
    upload
};
